﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Common.Utilities;
using Common.Utilities.Dispatcher;
using Workflows.Components.ETL.Properties;

namespace Workflows.Components.ETL
{
	/// <summary>
	/// 
	/// </summary>
	[Serializable]
	public class ExcelReaderComponent:WorkflowComponentBase
	{
		#region ctor
		/// <summary>
		/// 
		/// </summary>
		public ExcelReaderComponent()
			: base()
		{
			this.ComponentActivityType = WorkflowActivityType.SimpleActivity;
			this.ComponentCategory = WorkflowComponentCategory.ETL.ToString();
			this.ComponentName = "Excel Reader";
			this.Description = "Read excel file into data set containing one table for each worksheet";
			this.ComponentIcon = Resources.excel_file;
			this.ComponentImage = Resources.excelsrc_201;

			this._Instruction =
				new ExcelReaderInstruction(
                    this.ComponentID, Guid.Empty, string.Empty, string.Empty,
                    new Dictionary<string, Dictionary<string, SimpleDataType>>(), 
                    new Dictionary<string, Dictionary<string, int>>(), 
                    string.Empty, string.Empty, string.Empty, true, true);
			this._Output = new ExcelReaderOutput(this.ComponentID, Guid.Empty, string.Empty);
		}
		#endregion

		#region Overrides of WorkflowComponentBase
		private ExcelReaderInstruction _Instruction;
		/// <summary></summary>
		public override InstructionBase Instruction
		{
			get
			{
				return this._Instruction;
			}
			set
			{
				this._Instruction =(ExcelReaderInstruction) value;
			}
		}

		private ExcelReaderOutput _Output;
		/// <summary></summary>
		public override ResultBase Output
		{
			get
			{
				return this._Output;
			}
			set
			{
				this._Output =(ExcelReaderOutput) value;
			}
		}
		#endregion

		public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
		{
			XmlNode xNode = base.Serialize(ref xDoc, ref parentNode);
			this.Instruction.Serialize(ref xDoc, ref xNode);
			return xNode;
		}

		public override WorkflowComponentBase Instantiate(XmlNode xNode)
		{
			ExcelReaderComponent component = (ExcelReaderComponent)base.Instantiate(xNode);
			component.Instruction = component.Instruction.Instantiate(xNode.SelectSingleNode("Instruction"));
			return component;
		}
	}
}
